import pygame, sys, math, random
from pygame.locals import *
 
pygame.init()

class MSScrollingBackgroud:

    def __init__(self, screen, imageName):
        self.screen = screen
        self.imageOne = pygame.image.load(imageName)
        self.imageTwo = pygame.image.load(imageName)
        self.xOne = 0
        self.xTwo = self.imageOne.get_width()
    def Display(self):
        self.screen.blit(self.imageOne, (self.xOne,0))
        self.screen.blit(self.imageTwo, (self.xTwo,0))
    def Update(self, speed):
        if self.xOne < -1 * self.imageOne.get_width():
            self.xOne = self.xTwo + self.imageTwo.get_width()
        if self.xTwo < -1 * self.imageTwo.get_width():
            self.xTwo = self.xOne + self.imageOne.get_width()
        self.xOne -= speed
        self.xTwo -= speed
            
class MSEngine:
        def __init__(self, resolution,windowTitle):
            pygame.init()
            self.screen = pygame.display.set_mode(resolution)
            pygame.display.set_caption(windowTitle)
            self.clock = pygame.time.Clock()
        def Update(self, tick):
            pygame.display.update()
            self.clock.tick(tick)
        def GetScreen(self):
            return self.screen

class MSPlayer:
        def __init__(self,screen, image, xPos, yPos):
            self.screen = screen
            self.sprite = pygame.image.load(image)
            self.x = xPos
            self.firstY = yPos
            self.y = yPos
            self.sinx = 0
            self.speed = 1
            self.speedy = 1
        def Display(self):
            self.screen.blit(self.sprite, (self.x,self.y))
        def Update(self, oceanSpeed):
            self.keystate = pygame.key.get_pressed()
            if self.keystate[K_LEFT]:
                self.speed += 2.2
            if self.keystate[K_RIGHT]:
                self.speed -= 2.2
            if self.speed > 1:
                self.speed = self.speed / 1.07
            if self.speed < 0:
                self.speed = self.speed / 1.07
            if self.keystate[K_UP]:
                self.speedy += 2.2
            if self.keystate[K_DOWN]:
                self.speedy -= 2.2
            if self.speedy > 1:
                self.speedy = self.speedy / 1.07
            if self.speedy < 0:
                self.speedy = self.speedy / 1.07
            if self.sinx >=360:
                self.sinx = 0
            if self.y <= self.firstY:
                self.y = self.firstY
            if self.y >= (self.screen.get_height() - self.sprite.get_height()):
                self.y = (self.screen.get_height() - self.sprite.get_height())
            if (self.x >= (self.screen.get_width() - self.sprite.get_width())):
                self.x = (self.screen.get_width() - self.sprite.get_width())
            if (self.x <= 0):
                self.x = 0
            self.x -= oceanSpeed / 5 * self.speed
            self.y -= oceanSpeed / 5 * self.speedy
            self.y += math.sin(self.sinx)
            self.sinx += .07
            

            
   
            
            
